//package com.domdd.service.rocketmq;
//
//import com.alibaba.fastjson.JSON;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
//import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
//import org.apache.rocketmq.client.consumer.listener.MessageListener;
//import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
//import org.apache.rocketmq.common.message.MessageExt;
//import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
//
//import java.util.List;
//
///**
// * @author lw
// * @date 2022/3/2 4:04 下午
// */
//public class Consumer0 {
//
//    public static void main(String[] args) throws InterruptedException, MQClientException {
//
//        // Instantiate with specified consumer group name.
//        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("lw");
//
//        // Specify name server addresses.
//        consumer.setNamesrvAddr("47.98.252.4:9876");
//
//        // Subscribe one more more topics to consume.
//        consumer.subscribe("lw", "*");
//
//        //广播模式
////        consumer.setMessageModel(MessageModel.BROADCASTING);
////        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
//
//        //默认msgs里只有一条消息，可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
//        consumer.setConsumeMessageBatchMaxSize(1);
//        // Register callback to execute on arrival of messages fetched from brokers.
//        consumer.registerMessageListener(new MessageListenerConcurrently() {
//
//            @Override
//            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
//                                                            ConsumeConcurrentlyContext context) {
////                System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
////                System.out.println(context.);
//                msgs.forEach(m -> {
//                    System.out.print(new String(m.getBody()));
//                });
//                System.out.println("----");
//                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//            }
//        });
//
//        //Launch the consumer instance.
//        consumer.start();
//
//        System.out.printf("Consumer Started.%n");
//    }
//}
